Functions and procedures are well-known constructs that are used in creating modular programs. Nesting function and procedure calls further supports hierarchical program designs, thereby supporting multiple levels of design abstraction.
Functions and procedures often include parameters for passing data. A function typically has only input parameters, and a call to the function often returns a value. A procedure may have both input and output parameters. For ease of reference, functions and procedures are referenced herein as “routines.”
Many processor architectures use a register stack and a register renaming mechanism to pass parameter values between routine calls. The processor associates selected registers with parameters of a routine when a routine is called. The register stack includes multiple registers and a stack pointer that references the set of registers at the top of the stack for the most recently called routine. With each nested routine call, additional registers from the register stack are associated with the parameters of the called routine. Other registers that a routine uses during execution for temporary storage of data are referred to as “scratch” registers.
Tools that support analysis of an executing program must account for behavior of the register stack and a routine's usage of scratch registers in order to avoid corrupting data referenced by the routines in the program. Analysis of binary executable programs is performed to analyze program performance, verify correctness, and test correct runtime operation, for example. Some analyses are performed prior to runtime (static analysis), while other analyses are performed during runtime (dynamic analysis). For both static and dynamic analysis, however, the analysis is often performed at the routine level.
One category of analysis performed on executable programs is “instrumentation”. Instrumentation is generally used to gather runtime characteristics of a program. For example, the number of times that a routine is executed while the application is executing is determined through instrumentation. Such instrumentation is sometimes accomplished by inserting a call to a probe routine at a selected point in the program. The probe routine performs instrumentation-related operations.
When inserting a probe routine call, the instrumentation tool must preserve the contents of the register stack so that invocation of the probe routine does not corrupt the contents of the registers, which are associated with parameters of the routine from which the probe routine was called. One approach to preserving the register stack is to save the contents of registers on the memory stack of the calling routine. However, this is costly in terms of execution time, especially if the routine from which the probe routine was invoked is called many times during program execution.
A system and method that address the aforementioned problems, as well as other related problems, are therefore desirable.